package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.JtProductCategory;
import com.ruoyi.business.domain.vo.JtSupplierVo;
import com.ruoyi.common.annotation.RepeatSubmit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtSupplier;
import com.ruoyi.business.service.IJtSupplierService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商信息Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-29
 */
@Controller
@RequestMapping("/business/supplier")
public class JtSupplierController extends BaseController
{
    private String prefix = "business/supplier";

    @Autowired
    private IJtSupplierService jtSupplierService;

    @RequiresPermissions("business:supplier:view")
    @GetMapping()
    public String supplier()
    {
        return prefix + "/supplier";
    }

    /**
     * 查询供应商信息列表
     */
    @RequiresPermissions("business:supplier:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtSupplier jtSupplier)
    {
        startPage();
        List<JtSupplier> list = jtSupplierService.selectJtSupplierList(jtSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商信息列表
     */
    @RequiresPermissions("business:supplier:export")
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtSupplier jtSupplier)
    {
        List<JtSupplier> list = jtSupplierService.selectJtSupplierList(jtSupplier);
        ExcelUtil<JtSupplier> util = new ExcelUtil<JtSupplier>(JtSupplier.class);
        return util.exportExcel(list, "供应商信息数据");
    }

    /**
     * 新增供应商信息
     */
    @RequiresPermissions("business:supplier:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商信息
     */
    @RequiresPermissions("business:supplier:add")
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult addSave(JtSupplier jtSupplier)
    {
        return toAjax(jtSupplierService.insertJtSupplier(jtSupplier));
    }

    /**
     * 修改供应商信息
     */
    @RequiresPermissions("business:supplier:edit")
    @GetMapping("/edit/{supplierId}")
    public String edit(@PathVariable("supplierId") Long supplierId, ModelMap mmap)
    {
        JtSupplier jtSupplier = jtSupplierService.selectJtSupplierBySupplierId(supplierId);
        mmap.put("jtSupplier", jtSupplier);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商信息
     */
    @RequiresPermissions("business:supplier:edit")
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult editSave(JtSupplier jtSupplier)
    {
        return toAjax(jtSupplierService.updateJtSupplier(jtSupplier));
    }

    /**
     * 删除供应商信息
     */
    @RequiresPermissions("business:supplier:remove")
    @Log(title = "供应商信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtSupplierService.deleteJtSupplierBySupplierIds(ids));
    }

    /**
     * 查询分类列表
     */
    @GetMapping("/select/list")
    @ResponseBody
    public AjaxResult selectList()
    {
        JtSupplier param = new JtSupplier();
        param.setStatus(0);
        List<JtSupplierVo> list = jtSupplierService.selectJtSupplierVoList(param);

        AjaxResult ajax = new AjaxResult();
        ajax.put("code", 200);
        ajax.put("value", list);
        return ajax;
    }
}
